import {createRouter, createWebHistory} from 'vue-router'
import HomeView from '@/views/HomeView.vue'

/**
 * 创建Vue路由器实例
 * @param history - 路由历史模式，使用Web History API
 * @param routes - 路由配置数组，定义应用的所有路由规则
 * @returns 路由器实例
 */
const router = createRouter({
    history: createWebHistory(import.meta.env.BASE_URL),
    routes: [
        {
            path: '/', // 根路径
            redirect: '/home', // 重定向到首页
        },
        {
            path: '/home', // 根路径
            name: 'home',
            component: HomeView,
        },
        {
            path: '/register', // 根路径
            name: 'register',
            component: () => import('@/views/RegisterVierw.vue'),
        },
        {
            path: '/about', //  关于路径
            name: 'about',
            component: () => import('@/views/AboutView.vue'),
        },
        {
            path: '/news',
            name: 'news',
            component: () => import('@/views/NewsView.vue'),
            children: [ // 子路由
                {
                    path: 'detail/:id/:title/:content',
                    name: 'detail',
                    component: () => import('@/views/NewsDetailView.vue'),
                },
            ],
        },
        {
            path: '/product_details/:id/:title',
            name: 'product_details',
            component: () => import('@/views/ProductDetails.vue') // 懒加载组件
        },
        {
            path: '/:pathMatch(.*)*',  // 匹配任意路径
            name: 'NotFound',
            component: () => import('@/views/NotFound.vue') // 懒加载组件
        }
    ],
})

export default router

